<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/default}">
<head>
    <title>用户详情</title>
</head>
<body>
    <div layout:fragment="content" class="fade-in">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2><i class="fas fa-user me-2"></i>用户详情</h2>
            <div>
                <a th:href="@{/admin/users/{id}/edit(id=${user.id})}" class="btn btn-primary me-2">
                    <i class="fas fa-user-edit me-2"></i>编辑用户
                </a>
                <a href="/admin/users" class="btn btn-secondary">
                    <i class="fas fa-arrow-left me-2"></i>返回用户列表
                </a>
            </div>
        </div>
        
        <div th:if="${successMessage}" class="alert alert-success alert-dismissible fade show" role="alert">
            <i class="fas fa-check-circle me-2"></i>
            <span th:text="${successMessage}"></span>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
        
        <div class="row">
            <div class="col-md-6">
                <div class="card mb-4">
                    <div class="card-header">
                        <h5 class="mb-0"><i class="fas fa-id-card me-2"></i>基本信息</h5>
                    </div>
                    <div class="card-body">
                        <table class="table">
                            <tr>
                                <th style="width: 30%">ID</th>
                                <td th:text="${user.id}"></td>
                            </tr>
                            <tr>
                                <th>用户名</th>
                                <td th:text="${user.username}"></td>
                            </tr>
                            <tr>
                                <th>邮箱</th>
                                <td th:text="${user.email}"></td>
                            </tr>
                            <tr>
                                <th>角色</th>
                                <td>
                                    <span th:if="${user.role.name() == 'ADMIN'}" class="badge bg-danger">管理员</span>
                                    <span th:if="${user.role.name() == 'USER'}" class="badge bg-primary">用户</span>
                                </td>
                            </tr>
                            <tr>
                                <th>注册时间</th>
                                <td th:text="${#temporals.format(user.createdAt, 'yyyy-MM-dd HH:mm:ss')}"></td>
                            </tr>
                            <tr>
                                <th>最后更新</th>
                                <td th:text="${user.updatedAt != null ? #temporals.format(user.updatedAt, 'yyyy-MM-dd HH:mm:ss') : '未更新'}"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="card-footer">
                        <div class="d-flex justify-content-between">
                            <div th:if="${user.username != 'admin'}">
                                <form th:if="${user.role.name() == 'USER'}" th:action="@{/admin/users/{id}/role(id=${user.id})}" method="post" class="d-inline">
                                    <input type="hidden" name="role" value="ADMIN">
                                    <button type="submit" class="btn btn-warning">
                                        <i class="fas fa-user-shield me-2"></i>设为管理员
                                    </button>
                                </form>
                                <form th:if="${user.role.name() == 'ADMIN'}" th:action="@{/admin/users/{id}/role(id=${user.id})}" method="post" class="d-inline">
                                    <input type="hidden" name="role" value="USER">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="fas fa-user me-2"></i>设为普通用户
                                    </button>
                                </form>
                            </div>
                            <form th:if="${user.username != 'admin'}" th:action="@{/admin/users/{id}/delete(id=${user.id})}" method="post" class="d-inline"
                                  onsubmit="return confirm('确定要删除该用户吗？此操作不可撤销！')">
                                <button type="submit" class="btn btn-danger">
                                    <i class="fas fa-trash-alt me-2"></i>删除用户
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 用户发布的物品信息可以在这里添加 -->
        </div>
    </div>
</body>
</html> 